<%layout("/common/_layout.html"){ %>
<script type="text/javascript">

function changeStatus(url,id,targetStatus) {
    
    $.ajax({
        url : url,
        data : {"id":id,"target_status":targetStatus},
        dataType : "json",
        async : true,
        success : function(data) {
          //parent.swal({title: "配置成功!", text: data.message, type: "success",timer: 2000,   showConfirmButton: false});
          parent.layer.msg("配置: " + data.message);
        }
        
    });
    
}
 
$(function(){
    var $mycheckbox = $('.switch-button').find("input[type='checkbox']");
    $mycheckbox.each(function(){
        var myid = $(this).attr("id");
        $("#"+myid).on({
            'switchChange.bootstrapSwitch': function(event, state) {
              var id =$(this).attr("id") ;
              console.log("switch:"+id+":"+state);
              changeStatus("${base}/brand/changeStatus",id,state?1:0);
            }
        });
    });

  });
  
 
</script>

<%#ajax userTable:{%>
<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">商品管理</strong>
    /
    <small>品牌管理</small>
  </div>
</div>

<div class="am-g">
  <div class="am-u-sm-12">
    <form class="am-form" id="list-form" action="${base}/brand/list" method="post">
      <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
      <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
        <tbody>
          <tr>
            <th class="am-text-middle">名称</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="name" class="am-form-field am-input-sm" value="${name!}" />
              </div>
            </td>

            <th class="am-text-middle">创建时间</th>
            <td>
              <div class="am-u-sm-10">
                <div class="am-form am-form-inline">
                  <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                    <input type="text" class="am-form-field am-input-sm" id="starttime" value="${starttime!}" placeholder="开始日期" readonly data-am-datepicker></div>
                  <div class="am-form-group">至</div>
                  <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                    <input type="text" class="am-form-field am-input-sm" id="endtime" value="${endtime!}" placeholder="结束日期" readonly data-am-datepicker></div>
                </div>
              </div>
            </td>
          </tr>
          <tr>
            <td colspan="4">
              <div align='right'>
                <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="submit-btn">搜索</button>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>

  <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
    <div class="am-btn-toolbar" style="padding-left:.5rem;">
      <div class="am-btn-group am-btn-group-xs">
        <%if(so.hasPermission("BRAND_ADD")) {%>
        <div class="am-btn-group am-btn-group-xs am-form-file">
          <button type="button" id="bt_add" class="am-btn am-btn-default"  onclick="location.href='${base}/brand/add'">新增</button>
        </div>
        <%}%>
        <!--
           <%if(so.hasPermission("BRAND_DELETE")) {%>
        <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteAll('${base}/brand/delete')">
          <span class="am-icon-trash-o"></span>
          删除
        </button>
        <%}%>--></div>
    </div>
  </div>

  <div class="am-g">
    <div class="am-u-sm-12">
      <div class="am-scrollable-horizontal">
        <table class="am-table am-table-striped am-table-hover table-main">
          <thead>
            <tr class="am-text-nowrap">
              <th class="table-title">名称</th>
              <th class="table-title">创建时间</th>
              <th class="table-title">编辑者</th>
              <th class="table-title">修改时间</th>
              <!--<th class="table-title">是否启用</th>
            -->
            <th class="table-title" width="10px">描述</th>
            <th class="table-title">操作</th>
          </tr>
        </thead>
        <tbody>
          <%for(item in pager.list!){%>
          <tr>
            <!--<td>
            <input type="checkbox" name="ids" value="${item.id}"></td>
          -->
          <td>${item.name}</td>
          <td>${item.create_time}</td>
          <td>${item.operated_by}</td>
          <td>${item.operated_time,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
          <td style="word-break:break-all; word-wrap:break-all;width:40%">${item.description}</td>
          <td>
            <div class="am-btn-toolbar">
              <div class="am-btn-group am-btn-group-xs">
                <%if(so.hasPermission("BRAND_EDIT")) {%>
                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='${base}/brand/edit?id=${item.id}'">
                  <span class="am-icon-pencil-square-o"></span>
                  编辑
                </button>
                <%}%></div>
            </div>
          </td>
        </tr>
        <%}%></tbody>
    </table>
  </div>

  <div class="am-cf">
    <!-- 分页 -->
    <%if (pager.list.~size >
    0){%>
    <div class="am-fr">
      <% include("/admin/common_pager.tpl"){}%></div>
    <%}else{%>
    <div class="am-kai">
      <h3>没有找到任何记录!</h3>
    </div>
    <%}%></div>

</div>
</div>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="modal">
<div class="am-modal-dialog">
  <div class="am-modal-hd">
    <i class="am-icon-refresh am-icon-spin"></i>
    <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
  </div>
  <div class="am-modal-bd">正在处理，请稍等...</div>
</div>
</div>

<script type="text/javascript">
    $(function(){
      var keywordsObj = {};
      $("#submit-btn").on("click",function(){
        if($("#name").val())
          keywordsObj.name = $("#name").val();
        if($("#starttime").val())
          keywordsObj.starttime = $("#starttime").val();
         if($("#endtime").val())
          keywordsObj.endtime = $("#endtime").val();   
             
        var keywords = "";
        if(!$.isEmptyObject(keywordsObj)){
          keywords = JSON.stringify(keywordsObj);
        }
        console.log("keywords = "+ keywords);

        $("#keywords").val(keywords);
        $("#list-form").submit();
      });
    });
 
  </script>
<%}%>
<%}%>